﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.HVAC
{
	public partial class AnyLayTypeForm : System.Windows.Forms.Form
	{
		public int LayType
		{
			get
			{
				return this.type;
			}
		}

		public AnyLayTypeForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.userSetting = new UserSetting();
			this.ReadUserData();
		}

		private void ReadUserData()
		{
			string value = (this.userSetting.GetValue("RadiatorAnyLayType", "AlongWithWall") == "") ? "True" : this.userSetting.GetValue("RadiatorAnyLayType", "AlongWithWall");
			this.rdoAlongWithWall.Checked = Convert.ToBoolean(value);
			this.rdoAnyLay.Checked = !this.rdoAlongWithWall.Checked;
			this.cbNum.Checked = Convert.ToBoolean((this.userSetting.GetValue("RadiatorAnyLayType", "SetNum") == "") ? "True" : this.userSetting.GetValue("RadiatorAnyLayType", "SetNum"));
			this.cbDimension.Checked = Convert.ToBoolean((this.userSetting.GetValue("RadiatorAnyLayType", "SetDimension") == "") ? "True" : this.userSetting.GetValue("RadiatorAnyLayType", "SetDimension"));
			this.nuNum.Value = Convert.ToDecimal((this.userSetting.GetValue("RadiatorAnyLayType", "NuNum") == "") ? "6" : this.userSetting.GetValue("RadiatorAnyLayType", "NuNum"));
		}

		private bool SaveUserData()
		{
			this.IsSetNum = this.cbNum.Checked;
			this.Num = Convert.ToInt32(this.nuNum.Value);
			this.IsDimension = this.cbDimension.Checked;
			if (this.IsSetNum && this.Num <= 0)
			{
				YJKMessageBox.Show("片数必须大于0！");
				this.nuNum.Focus();
				return false;
			}
			this.type = Convert.ToInt32(this.rdoAlongWithWall.Checked);
			this.userSetting.WriteValue("RadiatorAnyLayType", "AlongWithWall", this.rdoAlongWithWall.Checked.ToString());
			this.userSetting.WriteValue("RadiatorAnyLayType", "SetNum", this.cbNum.Checked.ToString());
			this.userSetting.WriteValue("RadiatorAnyLayType", "SetDimension", this.cbDimension.Checked.ToString());
			this.userSetting.WriteValue("RadiatorAnyLayType", "NuNum", this.nuNum.Value.ToString());
			return true;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.SaveUserData())
			{
				base.DialogResult = DialogResult.OK;
				base.Close();
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void cbNum_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbNum.Checked)
			{
				this.nuNum.Enabled = true;
				return;
			}
			this.nuNum.Enabled = false;
		}

		private UserSetting userSetting;

		private int type;

		public bool IsSetNum;

		public int Num;

		public bool IsDimension = true;
	}
}
